package com.go.ssh.commons.web.listener;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.go.ssh.commons.Constants;
import com.go.ssh.point.model.OperationRoleModel;
import com.go.ssh.point.service.IOperationRoleService;

public class InitConfigListener implements ServletContextListener {
	@Override
	public void contextInitialized(ServletContextEvent sce) {
		ServletContext servletContext = sce.getServletContext();
		ApplicationContext ac = WebApplicationContextUtils
				.getRequiredWebApplicationContext(servletContext);
		IOperationRoleService operationRoleService = (IOperationRoleService) ac
				.getBean("operationRoleService");
		List<OperationRoleModel> roles = operationRoleService
				.getAllOperationRoles();
		servletContext.setAttribute(Constants.ROLE_MAP_KEY, roles);
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		// TODO Auto-generated method stub
	}

}